﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Security;
using stud.configurations;
using stud.DTOs;

/// <summary>
/// Summary description for BasePage
/// </summary>
public class BasePage : System.Web.UI.Page
{
    public BasePage()
    {
        PreRender += new EventHandler(BasePage_PreRender);
    }

    void BasePage_PreRender(object sender, EventArgs e)
    {
        PageInfo pageInfo = PageConfig.GetPageInfoByPageName(PageName);
        var userRoles = Roles.GetRolesForUser(Membership.GetUser().UserName).ToList();
        bool hasRole = false;
        foreach (var userRole in userRoles)
        {
            if (pageInfo.Roles.Contains(userRole))
            {
                hasRole = true;
                break;

            }
        }
        if (!hasRole)
            HttpContext.Current.Response.Redirect("~/Home.aspx");

    }



    public string PageName { get; set; }
}